#pragma once
#include "Common/TableData/SkillBuffCfg.h"
#include "Common/EventDefine.h"

enum BuffEffectInfoType
{
	effectTypeNone = 0,
	effectTypeDisperseMark = 1, //驱散mark
	effectTypeImmuneMark = 2, //免疫mark
	effectTypeContinuanceDamage = 3, //持续伤害
	effectTypeDizzy = 4, //眩晕
	effectTypeFrozen = 5, //冰冻
	effectTypeWinding = 6, //缠绕
	effectTypeHpShield = 7, //生命护盾
	effectTypeTargetMove = 8, //击退
	effectTypeInvisible = 9, //隐身
	effectTypeRefixSkill = 10, //修改技能
	effectTypeFlash = 11, //闪现
	effectTypeHaloDamage = 12, //光环持续伤害
	effectTypeHaloBeat = 13, //光环击退
	effectTypeSummonCreature = 14, //召唤
	effectTypeHaloDamageSquare = 15, //光环持续伤害矩形
	effectTypeDisperseBuffBagId = 16, //驱散buff bag id
	effectTypeImmuneBuffBagId = 17, //免疫buff bag id
	effectTypeOneHitKill = 18, //一击必杀
	effectTypeReduceSkillCd = 19, //减少技能冷却时间
	effectTypeSeeVisible = 20, //光合反影
	effectTypeAddHpOneTime = 21, //一次性加血
	effectTypeDelHpOneTime = 22, //一次性减血
	effectTypeDrap = 23, //拖拽
	effectTypeExchangeHp = 24, //交换血量百分比
	effectTypeNoSee  = 25, //致盲
	effectTypeMaBi = 27, //麻痹
	effectTypeAddGoldPercentForever = 28, //

	effectTypeAddDropPercentForever = 30,
	effectTypeZiBao = 31,
	effectTypeWuDi = 32,

	effectTypeAddGoldPercent = 34,
	effectTypeAddDropPercent = 35,
	effectTypeAddBuffBag = 36,

	effectTypeBossShield = 58,



	effectTypeChangeAP = 101,
	effectTypeChangeAPPercent = 102,
	effectTypeChangeMat = 103,
	effectTypeChangeMatPercent = 104,
	effectTypeChangeDP = 105,

	effectTypeChangeDPPercent = 106,   //修改物理防御百分比
	effectTypeChangeMDP = 107,				//修改魔法防御固定值
	effectTypeChangeMDPPercent = 108,		//修改魔法防御百分比
	effectTypeChangeMaxHp = 109,		//修改最大生命固定值
	effectTypeChangeMaxHpPercent = 110, //修改最大生命百分比
	effectTypeChangeMaxMP = 111,			//修改最大魔法固定值
	effectTypeChangeMaxMPPercent = 112,		//修改最大魔法百分比
	effectTypeAddHp = 113, //持续性加血
	effectTypeAddMp = 114, //持续性加蓝
	effectTypeChangeHit = 115, //改变命中固定值
	effectTypeChangeDodge = 116, //改变闪避固定值
	effectTypeChangeCrit = 117, //改变暴击固定值
	effectTypeChangeToughNess = 118, //改变韧性固定值
	effectTypeChangeMovePercent = 119, //修改移动速度百分比
	effectTypeChangeAttackPercent = 120, //改变攻击速度百分比
	effectTypeChangeCollectPercent = 121, //改变采集速度百分比
	effectTypeChangeExtraDamage = 122, //改变额外伤害
	effectTypeChangeReduceDamage = 123, //改变额外免伤
	effectTypeChangeCollectCreatureRate = 124, //提升采集资源伴生物出现的概率
	effectTypeChangeCollectDouble = 125, //采集资源双倍获取

	effectTypeUseSpecialEffect = 500,
};

enum BuffInfoEndType
{
	BuffInfoNormalEnd = 0,//		0 = 正常时间内结束
	BuffInfoLeaveSceneEnd = 1,//	1 = 脱离副本结束
	BuffInfoDeadEnd = 2,//	2 = 死亡结束
	BuffInfoSwitchScene = 3, //3 = 切换场景结束
	BuffInfoLeaveSafeAreaEnd = 4,// = 脱离安全区结束
	BuffInfoReleaseSkillEnd = 6,//	6 = 主动释放技能结束
	BuffInfoBeDamagedEnd = 7,//	7 = 受到伤害结束
	BuffInfoNoCountEnd = 8,//	8 = 次数用尽结束
	BuffInfoUseAttackComputeSkill = 9, //使用攻防运算的技能后结束
};

enum BuffStateBagSuperPosition
{
	BuffStateBagNoSuperPosition = 0,//		0 = 永不叠加（当有1个同ID时，永不接受）
	BuffStateBagDirectlyOverrides = 1,//	1 = 直接覆盖
	BuffStateBagLongTimerOverrides = 2,//	2 = 持续时间长覆盖持续时间短
	BuffStateBagFirstBiggerOverrides = 3,//	3 = 第一效果值大的覆盖小的，否则不覆盖
	BuffStateBagEffectSuperPosition = 4,//	4 = 不覆盖，效果叠加（当叠加大于5层时，不再叠加）
};

enum BuffBagStatus
{
	BUFF_BAG_STATUS_CREATED = 0,		//创建
	BUFF_BAG_STATUS_REFIX_START = 1, //立马生效
	BUFF_BAG_STATUS_DELAYED_START = 2,	//延时生效
	BUFF_BAG_STATUS_KILLING_START = 3, //击杀目标生效
	BUFF_BAG_STATUS_BE_ATTACTED_START = 4, //受敌对阵营攻击时生效
	BUFF_BAG_STATUS_ATTACK_START = 5, //对敌对阵营攻击时生效
	BUFF_BAG_STATUS_ROLE_PU_ATTACK_START = 6, //角色攻击时生效
	BUFF_BAG_STATUS_PET_PU_ATTACK_START = 7, //精灵普攻生效
	BUFF_BAG_STATUS_SECOND_TRIGGER_START = 8, //二次触发生效
	BUFF_BAG_STATUS_WILLING_DIED_START = 9, //即死触发
	BUFF_BAG_STATUS_USE_SKILL = 10, //use skill
	BUFF_BAG_STATUS_SKILL_TRIGGER_START = 11, //特定技能触发
	BUFF_BAG_STATUS_PROP_AND_SKILL_TRIGGER_START = 12, //特定职业特定技能触发
};

enum BuffTargetType
{
	BUFF_BAG_TARGET_TYPE_ENEMY = 0, //目标是敌方
	BUFF_BAG_TARGET_TYPE_SELF = 1, //目标是自己
};

enum
{
	BuffStateBagEffectSuperPositionMaxCount = 5, //效果叠加最大层数
};

struct BuffEffectCfgInfo
{
	BuffEffectCfgInfo()
	{
		m_type = effectTypeNone;
	}

	int32_t m_type;
	std::vector<int32_t>  m_param;
};

struct BuffBagEffectCfgInfo
{
public:
	BuffBagEffectCfgInfo()
	{
		m_pCfgInfo = nullptr;
		m_disperseEffectMark = 0;
		m_immuneEffectMark = 0;

		m_startTypeValueProf = 0;
		m_startTypeValueSkillType = 0;
	}

	~BuffBagEffectCfgInfo()
	{

	}

	//是否对状态包info免疫
	bool IsImmuneEffect(const BuffBagEffectCfgInfo& info) const
	{
		if (HasImmuneMark())
		{
			return IsImmuneEffectByMark(info.m_pCfgInfo->mask);
		}
		else if (HasImmuneBuffBagId())
		{
			return IsImmuneEffectByBuffBagId(info.m_pCfgInfo->stateBagID);
		}
		return false;
	}

	//是否驱散状态包info
	bool IsDisperseEffect(const BuffBagEffectCfgInfo& info) const
	{
		if (HasDisperseMark())
		{
			return IsDisperseEffectByMark(info.m_pCfgInfo->mask);
		}
		else if (HasDisperseBuffBagId())
		{
			return IsDisperseEffectByBuffBagId(info.m_pCfgInfo->stateBagID);
		}
		return false;
	}
	//通过掩码计算十分免疫
	bool IsImmuneEffectByMark(uint32_t mark) const
	{
		return (m_immuneEffectMark & mark) != 0 ? true : false;
	}
	//通过状态包id计算免疫
	bool IsImmuneEffectByBuffBagId(uint32_t buffStateBagId) const
	{
		return std::find(m_immuneBuffBagId.begin(), m_immuneBuffBagId.end(), buffStateBagId) != m_immuneBuffBagId.end();
	}
	//通过掩码计算是否驱散
	bool IsDisperseEffectByMark(uint32_t mark) const
	{
		return (m_disperseEffectMark & mark) != 0 ? true : false;
	}
	//通过状态包id计算是否驱散
	bool IsDisperseEffectByBuffBagId(uint32_t buffStateBagId) const
	{
		return std::find(m_disperseBuffBagId.begin(), m_disperseBuffBagId.end(), buffStateBagId) != m_disperseBuffBagId.end();
	}
	//状态包有没有免疫效果
	bool HasImmuneEffect() const
	{
		if (m_immuneEffectMark != 0 || m_immuneBuffBagId.size() != 0)
		{
			return true;
		}
		return false;
	}
	//状态有没有免疫掩码
	bool HasImmuneMark() const
	{
		return m_immuneEffectMark != 0;
	}
	//状态包有没有免疫状态包id
	bool HasImmuneBuffBagId() const
	{
		return m_immuneBuffBagId.size() != 0;
	}
	//状态包有没有驱散效果
	bool HasDisperseEffect() const
	{
		if (m_disperseBuffBagId.size() != 0 || m_disperseEffectMark != 0)
		{
			return true;
		}
		return false;
	}
	//状态包有没有驱散掩码
	bool HasDisperseMark() const
	{
		return m_disperseEffectMark != 0;
	}
	//状态包有没有要驱散的状态包id
	bool HasDisperseBuffBagId() const
	{
		return m_disperseBuffBagId.size() != 0;
	}

	bool IsContainEndType(int32_t endType) const
	{
		return std::find(m_endType.begin(), m_endType.end(), endType) != m_endType.end();
	}

	bool IsContainStartValue(int32_t startValue) const
	{
		return std::find(m_startTypeValue.begin(), m_startTypeValue.end(), startValue) != m_startTypeValue.end();
	}

public:
	const SkillBuffCfgInfo* m_pCfgInfo;
	std::vector<int32_t>	m_endType; //有序的，方面查找
	std::vector<BuffEffectCfgInfo> m_buffList;
	uint32_t	m_disperseEffectMark;
	uint32_t	m_immuneEffectMark;
	std::vector<uint32_t>	m_disperseBuffBagId;
	std::vector<uint32_t>	m_immuneBuffBagId;
	std::vector<int32_t> m_startTypeValue;
	uint32_t m_startTypeValueProf;
	uint32_t m_startTypeValueSkillType;
};


class BuffBagEffectCfgMgr : public ManualSingleton<BuffBagEffectCfgMgr>
{
	friend ManualSingleton < BuffBagEffectCfgMgr >;
	typedef std::unordered_map<uint32_t, BuffBagEffectCfgInfo> BuffBagMap;
	typedef BuffBagMap::iterator BuffBagMapIter;
	typedef BuffBagMap::const_iterator BuffBagMapConstIter;
public:

public:
	BuffBagEffectCfgMgr();
	~BuffBagEffectCfgMgr();
public:
	bool Init();
	bool UnInit();
public:
	const BuffBagEffectCfgInfo* FindBuffBag(uint32_t buffBagId) const;
protected:
	BuffBagMap		m_buffBagMap;
};


#define g_MakeBuffBagEffectCfgMgr() (BuffBagEffectCfgMgr::Instance())
#define g_GetBuffBagEffectCfgMgr()  (BuffBagEffectCfgMgr::GetInstance())
#define g_DelBuffBagEffectCfgMgr()  (BuffBagEffectCfgMgr::Destroy())
